# -*- coding: utf-8 -*-
'''
    程序创建模块，在这里创建flask程序
'''

from config import config, os, basedir
from flask import Flask

def create_app(config_name):
    '''程序工厂函数'''

    app = Flask(__name__, 
            template_folder=os.path.join(basedir, 'app', 'frontend', 'templates'),
            static_folder=os.path.join(basedir, 'app', 'frontend', 'static')
        )
    app.config.from_object(config[config_name])
    config[config_name].init_app(app)

    # 初始化扩展

    # 注册蓝图
    from .main import main as main_blueprint
    from .admin import admin as admin_blueprint
    from .user import user as user_blueprint

    app.register_blueprint(main_blueprint)
    app.register_blueprint(admin_blueprint, url_prefix='/admin')
    app.register_blueprint(user_blueprint)

    return app
